<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

/*
|--------------------------------------------------------------------------
| AIR2 Source View
|--------------------------------------------------------------------------
| Load inline data for the source profile page
|   $base_url     - base url of this source
|   $source       - json of this source
|   $submission   - json for source's submissions
|   $stats        - json for the source's statistics
|   $notes        - json for the source's annotations
|   $activities   - json for the source's activity
|   $tags         - json for the source's tags
|   $facts        - json for the source's facts
|   $credentials  - json for the source's credentials
|   $specialties  - json for the source's specialties
*/
?>
<script type="text/javascript">
    AIR2.Source.BASEURL   = '<?php echo $base_url; ?>';
    AIR2.Source.SUBMSRCH  = <?php echo isset($sub_srch) ? "'$sub_srch'" : 'null'; ?>;
    AIR2.Source.SUMMDATA  = <?php echo json_encode($src); ?>;
    AIR2.Source.STATSDATA = <?php echo json_encode($stats); ?>;
    AIR2.Source.SUBMDATA  = <?php echo json_encode($subm); ?>;
    AIR2.Source.SVDATA    = <?php echo json_encode($src_vita); ?>;
    AIR2.Source.ANNOTDATA = <?php echo json_encode($annot); ?>;
    AIR2.Source.ACTIVDATA = <?php echo json_encode($act); ?>;
    AIR2.Source.SFDATA    = <?php echo json_encode($facts); ?>;
    AIR2.Source.TAGDATA   = <?php echo json_encode($tag); ?>;
    AIR2.Source.FLDATA    = <?php echo json_encode($fl_data); ?>;
    AIR2.Source.ORGDATA   = <?php echo json_encode($org_data); ?>;
    AIR2.Source.STATES    = <?php echo json_encode($states); ?>;
    AIR2.Source.COUNTRIES = <?php echo json_encode($countries); ?>;

    AIR2.Source.contextPhone = function(srcPhoneObjArray, context) {
        if (!srcPhoneObjArray) return "unknown source phone";
        var sphnumber = '';
        
        for ( var i in srcPhoneObjArray ) {
            if ( srcPhoneObjArray[i].sph_context == context ) {
                sphnumber = srcPhoneObjArray[i].sph_number;
            }
        }
        
        return sphnumber;
    }

    AIR2.Source.primaryPhone = function(srcPhoneObjArray) {
        if (!srcPhoneObjArray) return "unknown source phone";
        var sphnumber = '';
        
        for ( var i in srcPhoneObjArray ) {
            if ( srcPhoneObjArray[i].sph_primary_flag ) {
                sphnumber = srcPhoneObjArray[i].sph_number;
            }
        }
        return sphnumber;
    }

    AIR2.Source.primaryEmail = function(srcEmailObjArray) {
        if (!srcEmailObjArray) return "unknown source email";
        var sememail = '';
        
        for ( var i in srcEmailObjArray ) {
            if ( srcEmailObjArray[i].sem_primary_flag ) {
                sememail = srcEmailObjArray[i].sem_email;
            }
        }
        return sememail;
    }

    AIR2.Source.setActivityIcon = function(values){
        if (values.ActivityMaster.activities_type == 'I')
            return 'air2-source-activities-other';
        else if (values.ActivityMaster.actm_type == 'S')
            return 'air2-source-activites-status';
        else if (values.ActivityMaster.actm_type == 'C')
            return 'air2-source-activities-analyst';
        else
            return 'air2-source-activities-other';
    }

    AIR2.Source.setSubject = function(values){
        if (values.ActivityMaster.actm_type == 'I')
            return AIR2.Format.sourceName(values.Source, true);
        else if (values.ActivityMaster.actm_type == 'S')
            return 'Status change: ';
        else if (values.ActivityMaster.actm_type == 'C')
            return "An analyst ";
        else
            return "Other: ";
    }
    

    Ext.onReady(AIR2.Source);
</script>
